﻿/*
 * Created by SharpDevelop.
 * User: Byo
 * Date: 11/18/2009
 * Time: 10:46 PM
 */
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Byo.Win32;

namespace CmdEx
{
	internal sealed class Program
	{
        public static bool IsFormHidden;    
        // For Checking Form is Currently Hidden or Not
        public static IntPtr WindowHandle;  
        // Handle To Main Window, Registered at First Run of 'HideOrUnhideWindow' Method
        public static bool firstRun;     


	    [STAThread]
		private static void Main(string[] args)
		{
		    //KeyboardHook.SetHook(() => MessageBox.Show("Test !"), KeyboardHook.BeginKeys.Control_Shift,KeyboardHook.EndKey.A);
            try
            {
                firstRun = true;

                Helper.SetGlobalHook(HideOrUnhideWindow, Helper.BeginKeys.Control, Helper.EndKey.Tilda);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                MainForm mf = new MainForm();
                Application.Run(mf);
            }
            finally
            {
                Helper.UnhookGlobalHook();
            }
		}
        

        public static void HideOrUnhideWindow()
        {
            // for registering main form window handle at first call to HideOrUnhideWindow Method
            if (firstRun)
                WindowHandle = Process.GetCurrentProcess().MainWindowHandle;
            //if (WindowHandle == 0) Process
                firstRun = false;

                if (!IsFormHidden)
            {
                Helper.ShowAsync(WindowHandle, 0);
                IsFormHidden = true;
            }
            else
            {
                Helper.ShowAsync(WindowHandle, 9);
                IsFormHidden = false;
            }
        }

	}
}
